# -*- coding: utf-8 -*-
# -*- coding: utf-8 -*-
from utils.operators.cluster_for_spark_sql_operator import SparkSqlOperator
from datetime import timedelta

from jms_dm_todo.dim.dim_frm_network_info_desc import jms_dim__dim_frm_network_info_desc
from jms_dm_todo.dm.dm_frm_network_summary_dt_over import jms_dm__dm_frm_network_summary_dt_over

jms_dm__dm_frm_network_summary_month_dt = SparkSqlOperator(
    task_id='jms_dm__dm_frm_network_summary_month_dt',
    task_concurrency=1,
    pool_slots=2,
    master='yarn',
    execution_timeout=timedelta(hours=1),
    email=['jokic.wang@jtexpress.com'],
    name='jms_dm__dm_frm_network_summary_month_dt_{{ execution_date | date_add(1) | cst_ds }}',
    sql='jms_dm_todo/dm/dm_frm_network_summary_month_dt/execute.sql',
    driver_memory='8G',
    driver_cores=1,
    executor_cores=8,
    executor_memory='8G',
    num_executors=22,  # spark.dynamicAllocation.enabled 为 True 时，num_executors 表示最少 Executor 数
    conf={
        'spark.dynamicAllocation.enabled': 'false',  # 动态资源开启
        'spark.shuffle.service.enabled': 'false',  # 动态资源 Shuffle 服务开启
        'spark.dynamicAllocation.maxExecutors': 40,  # 动态资源最大扩容 Executor 数
        'spark.dynamicAllocation.cachedExecutorIdleTimeout': 60,  # 动态资源自动释放闲置 Executor 的超时时间(s)
        'spark.sql.sources.partitionOverwriteMode': 'dynamic',  # 允许删改已存在的分区
        'spark.executor.memoryOverhead': '2G',  # 堆外内存
        'spark.sql.shuffle.partitions': 360,
        'spark.executor.extraJavaOptions': '-XX:+UseG1GC -XX:ParallelGCThreads=8',
        'spark.yarn.maxAppAttempts': 1,
        'spark.locality.wait.node': '50ms'
    },
    # hiveconf={
    #     'hive.exec.dynamic.partition': 'true',  # 动态分区
    #     'hive.exec.dynamic.partition.mode': 'nonstrict',
    #     'hive.exec.max.dynamic.partitions': 20,  # 每天生成 20 个分区
    #     'hive.exec.max.dynamic.partitions.pernode': 20  # 每天生成 20 个分区
    # },
)

jms_dm__dm_frm_network_summary_month_dt << [
    jms_dim__dim_frm_network_info_desc,
    jms_dm__dm_frm_network_summary_dt_over
]
